import 'dart:convert';

import 'package:equatable/equatable.dart';

class VideoSource extends Equatable {
  final int? id;
  final String? name;
  final String? url;
  final String? thumbnailUrl;

  const VideoSource({this.id, this.name, this.url, this.thumbnailUrl});

  factory VideoSource.fromMap(Map<String, dynamic> data) => VideoSource(
        id: data['id'] as int?,
        name: data['name'] as String?,
        url: data['url'] as String?,
        thumbnailUrl: data['thumbnailUrl'] as String?,
      );

  Map<String, dynamic> toMap() => {
        'id': id,
        'name': name,
        'url': url,
        'thumbnailUrl': thumbnailUrl,
      };

  /// `dart:convert`
  ///
  /// Parses the string and returns the resulting Json object as [VideoSource].
  factory VideoSource.fromJson(String data) {
    return VideoSource.fromMap(json.decode(data) as Map<String, dynamic>);
  }

  /// `dart:convert`
  ///
  /// Converts [VideoSource] to a JSON string.
  String toJson() => json.encode(toMap());

  VideoSource copyWith({
    int? id,
    String? name,
    String? url,
    String? thumbnailUrl,
  }) {
    return VideoSource(
      id: id ?? this.id,
      name: name ?? this.name,
      url: url ?? this.url,
      thumbnailUrl: thumbnailUrl ?? this.thumbnailUrl,
    );
  }

  @override
  bool get stringify => true;

  @override
  List<Object?> get props => [id, name, url, thumbnailUrl];
}
